package com.onegene.pdf;

import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.WriterProperties;
import org.xhtmlrenderer.pdf.ITextFontResolver;

import java.io.*;

public class TestHtml2PDF {

    public static void main(String[] args) throws IOException {
        //// IO
        File htmlSource = new File("D:/html/2.html");
        //File pdfDest = new File("D:/html/test1.pdf");
        //// pdfHTML specific code
        //ITextFontResolver fontResolver = renderer.getFontResolver();
        //ConverterProperties converterProperties = new ConverterProperties();
        //HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest),converterProperties);

        ConverterProperties properties = new ConverterProperties();
        properties.setFontProvider(new DefaultFontProvider(true, true, true));
        properties.setBaseUri("D:/html/");
        String html = "<h1>Test</h1><p>Hello World 你好世界</p><img src='http://www.ylmfwin100.com/templets/skin/img/logo.png'/>";
        File file = new File("d:/html/demo3.pdf");
        PdfWriter writer = new PdfWriter("d:/html/target_pdf.pdf",
                new WriterProperties().setFullCompressionMode(true));
        PdfDocument pdf = new PdfDocument(writer);
        pdf.setTagged();
        //HtmlConverter.convertToPdf(html, pdf,properties);
        HtmlConverter.convertToPdf(new FileInputStream(htmlSource), pdf,properties);
    }

}
